package com.oracle.oa.action;

import java.text.SimpleDateFormat;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.oracle.oa.biz.ManualSignBiz;
import com.oracle.oa.biz.UserInfoBiz;
import com.oracle.oa.biz.impl.OperatelogBizImpl;
import com.oracle.oa.entity.Manualsign;
import com.oracle.oa.entity.Userinfo;

public class DoSignIn extends ActionSupport implements SessionAware {

	public String signtime;
	public String signin;
	public String signout;
	public String signdesc;
	public Long userid;
	
	public String date;
	public String time;
	
	
	Map<String, Object> session;
	
	UserInfoBiz ubiz;
	ManualSignBiz msbiz;
	
	SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	SimpleDateFormat sdf=new SimpleDateFormat("HH:mm");
	
	public String signin(){
		
		//接受数据
		userid = (Long) session.get("userid");
		//通过id查询用户
		Userinfo user=(Userinfo) ubiz.getById(Userinfo.class, userid);
		signtime=sf.format(session.get("now"));//时间
		
		//构造签到信息
		Manualsign manualsign=new Manualsign(user,signtime,signdesc,"签到");
		manualsign.setSigntag("签到");
		//插入操作日志
		OperatelogBizImpl.add("签到", user.getUsername()+"签到");
		//插入数据库新的签到信息
		msbiz.save(manualsign);
		session.put("manualsign", manualsign);
		return SUCCESS;
	}
	public String signoff(){
		
		//接受数据
		userid = (Long) session.get("userid");
		//通过id查询用户
		Userinfo user=(Userinfo) ubiz.getById(Userinfo.class, userid);
		signtime=sf.format(session.get("now"));//时间
		Manualsign manualsign=null;
		//构造签到信息
		if(date!=null){
			signtime=date+" "+time;
			manualsign=new Manualsign(user,signtime,signdesc,"签退");
			//插入操作日志
			OperatelogBizImpl.add("签退", user.getUsername()+"签退");
		}else{
			manualsign=new Manualsign(user,signtime,signdesc,"签退");
			//插入操作日志
			OperatelogBizImpl.add("签退", user.getUsername()+"签退");
		}
		
		//插入数据库新的签到信息
		msbiz.save(manualsign);
		session.put("manualsign", manualsign);
		return SUCCESS;
	}
	public String signbu(){
		
		return ERROR;
	}

	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
	}
	public String getSigntime() {
		return signtime;
	}
	public void setSigntime(String signtime) {
		this.signtime = signtime;
	}
	public String getSignin() {
		return signin;
	}

	public void setSignin(String signin) {
		this.signin = signin;
	}

	public String getSignout() {
		return signout;
	}

	public void setSignout(String signout) {
		this.signout = signout;
	}

	public String getSigndesc() {
		return signdesc;
	}

	public void setSigndesc(String signdesc) {
		this.signdesc = signdesc;
	}
	public Long getUserid() {
		return userid;
	}
	public void setUserid(Long userid) {
		this.userid = userid;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	public UserInfoBiz getUbiz() {
		return ubiz;
	}
	public void setUbiz(UserInfoBiz ubiz) {
		this.ubiz = ubiz;
	}
	public ManualSignBiz getMsbiz() {
		return msbiz;
	}
	public void setMsbiz(ManualSignBiz msbiz) {
		this.msbiz = msbiz;
	}
	
	
}
